//logs.js
var util = require('../../utils/util.js');
var mpage = 1;
var mparam = null;
var app = getApp();
Page({
    data: {
        goodsList: null,
        sortFlag: '',
        pricehigh: true,
        priceSrc: '/images/arrow-up.png',
        priceSrc1: '/images/arrow-down.png',
        quanlitySrc: '/images/arrow-down.png',
        commentsSrc: '/images/arrow-down.png',
        windowwidth: app.globalData.deviceInfo.windowWidth,
        windowheight: app.globalData.deviceInfo.windowHeight
    },
    
    //获取商品列表数据
    getNetData: function () {
        wx.showToast({
            title: '加载中',
            icon: 'loading',
            duration: 10000
        });
        var that = this;
        var murl = `/c2mwebservice/api/v2/public/goods/conditions/?conditions=${mparam.keyWord}&page=${mpage}&sortFlag=${this.data.sortFlag}`;
        //https://www.magicmanufactory.com/c2mwebservice/api/v2/public/goods/conditions/?conditions=西裤&page=1&sortFlag=
        //请求数据
        console.log(murl)
        util.request(murl, function (dataJson) {
            wx.hideToast();
            if (mpage == 1) {
                that.setData({
                    goodsList: dataJson.returnData.rows,
                    loadingHidden: true
                })
            }
            else {
                that.setData({
                    goodsList: that.data.goodsList.concat(dataJson.returnData.rows),
                    loadingHidden: true
                })
            }
        }, function (reason) {
            wx.hideToast();
        });
    },
    lower: function (e) {
        mpage = mpage + 1;
        this.getNetData();
    },
    upper: function (e) {
        mpage = 1;
        this.getNetData();
    },
 
    onLoad: function (param) {
        mparam = param;
        console.log("--------------------->" + param)
        mpage = 1;
        this.getNetData();
    },

    onShow: function () {
    },
    //价格排序
    setPrice: function (e) {
        this.data.pricehigh = !this.data.pricehigh;
        if (this.data.pricehigh) {
            this.setData({
                sortFlag: 'price_decending',
                priceSrc: '/images/arrow-up.png',
                priceSrc1: '/images/arrow-downS.png',
                quanlitySrc: '/images/arrow-down.png',
                commentsSrc: '/images/arrow-down.png'
            });
        } else {
            this.setData({
                sortFlag: 'price_ascending',
                priceSrc: '/images/arrow-upS.png',
                priceSrc1: '/images/arrow-down.png',
                quanlitySrc: '/images/arrow-down.png',
                commentsSrc: '/images/arrow-down.png'
            });
        }
        this.getNetData();
    },
    //销量排序
    setShouliang: function (e) {
        this.setData({
            sortFlag: 'quantity',
            priceSrc: '/images/arrow-up.png',
            priceSrc1: '/images/arrow-down.png',
            quanlitySrc: '/images/arrow-downS.png',
            commentsSrc: '/images/arrow-down.png',
            pricehigh: true,
        });
        this.getNetData();
    },
    //好评排序
    setHaoping: function (e) {
        this.setData({
            sortFlag: 'comments',
            priceSrc: '/images/arrow-up.png',
            priceSrc1: '/images/arrow-down.png',
            quanlitySrc: '/images/arrow-down.png',
            commentsSrc: '/images/arrow-downS.png',
            pricehigh: true,
        });
        this.getNetData();
    },
    onShareAppMessage: function () {
        return {
            title: 'Cotte',
            desc: '酷特智能'
        }
    }
})